#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QFileDialog>
#include <QDialog>
#include <QVBoxLayout>
#include <QPushButton>

MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), m_ui(new Ui::MainWindow)
{
    m_ui->setupUi(this);
    
    dataBoard = new DataBoard(this);
    m_ui->dock_dataBoard->setWidget(dataBoard);
    m_ui->action_dataBoard->setChecked(true);

    connect(this, SIGNAL(newFileAdded(QStringList)), dataBoard, SLOT(addNewFiles(QStringList)));
}

MainWindow::~MainWindow()
{
    delete m_ui;
}

void MainWindow::changeEvent(QEvent *e)
{
    QMainWindow::changeEvent(e);
    switch (e->type()) {
    case QEvent::LanguageChange:
        m_ui->retranslateUi(this);
        break;
    default:
        break;
    }
}

void MainWindow::on_action_open_triggered()
{
    QStringList newFilePathes = QFileDialog::getOpenFileNames(this, "select one or more data files", "", "");
    emit newFileAdded(newFilePathes);
}

void MainWindow::on_action_close_triggered()
{
//    QDialog *dialog = new QDialog(this);
//    QVBoxLayout *layout = new QVBoxLayout(dialog);
//    QPushButton *button_OK = new QPushButton(tr("OK"), dialog);
//    QPushButton *button_cancel = new QPushButton(tr("Cancel"), dialog);
}

void MainWindow::on_action_quit_triggered()
{
    this->close();
}


void MainWindow::on_action_dataBoard_triggered(bool checked)
{
    if (checked == false) {
        m_ui->dock_dataBoard->setVisible(false);
    } else {
        m_ui->dock_dataBoard->setVisible(true);
    }
}
